package com.xm;

public class StringBuffer03 {
    public static void main(String[] args) {
        /*
         * 当对字符串进行修改的时候，需要使用 StringBuffer 和 StringBuilder 类。不产生新的未使用对象
         * StringBuilder 的方法不是线程安全的（不能同步访问）。但相较 StringBuffer 有速度优势
         * */
        StringBuilder sb = new StringBuilder(10);
        System.out.println(sb.append("Runoob67"));
        System.out.println(sb.capacity());
        System.out.println(sb.append("!"));
        System.out.println(sb.insert(8, "Java"));
        System.out.println(sb.delete(6, 7));
        System.out.println("容量："+sb.capacity());

        StringBuffer stringBuffer = new StringBuffer("菜鸟教程官网：");
        System.out.println(stringBuffer.capacity());
        stringBuffer.append("www");
        stringBuffer.append(".runoob");
        stringBuffer.append(".com");
        System.out.println(stringBuffer);
        System.out.println(stringBuffer.capacity());
    }
}
